import { http } from '@/utils/http/axios';

/**
 * @description: 根据用户id获取用户菜单
 */
export function adminMenus() {
  return http.request({
    url: '/admin/menu/userMenu',
    method: 'GET',
  });
}

/**
 * 获取tree菜单列表
 * @param params
 */
export function getMenuList(params?) {
  return http.request({
    url: '/admin/menu/list',
    method: 'GET',
    params,
  });
}

/**
 *
 * @param id 新的接口
 * @returns
 */
export function getMenu(id) {
  return http.request({
    url: '/admin/menu',
    params: { parentId: id },
    method: 'get',
  });
}

export function fetchMenuTree(lazy, parentId) {
  return http.request({
    url: '/admin/menu/treeMenu',
    method: 'get',
    params: { lazy: lazy, parentId: parentId },
  });
}

export function addObj(obj) {
  return http.request({
    url: '/admin/menu/create',
    method: 'post',
    data: obj,
  });
}

export function getObj(id) {
  return http.request({
    url: '/admin/menu/' + id,
    method: 'get',
  });
}

export function delObj(id) {
  return http.request({
    url: '/admin/menu/' + id,
    method: 'delete',
  });
}

export function putObj(obj) {
  return http.request({
    url: '/admin/menu/update',
    method: 'put',
    data: obj,
  });
}

export function clearMenuCache() {
  return http.request({
    url: '/admin/menu/cache',
    method: 'delete',
  });
}
